<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:cb="livcos.org/ns/clipboard"
  exclude-result-prefixes="cb">
  
  <xsl:import href="../../style/base.xsl" />
  
  <xsl:output encoding="UTF-8"
    doctype-public="-//W3C//DTD HTML 4.01//EN"
    doctype-system="http://www.w3.org/TR/html4/strict.dtd"/>
  
  <xsl:variable name="editJob" select="'/livcos.org/web/editor/clipboard/Edit.job'"/>

  <xsl:template match="/">
    <html id="{$viewObjId}">
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>Clipboard</title>
        <link href="../../css/global.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="../../script/E.js"><!-- --></script>
        <script type="text/javascript" src="../../script/util.js"><!-- --></script>
      </head>
      <body>
        <h2>Clipboard Entries</h2>
        <form action="{$toRootPath}{$editJob}" method="POST">
          <input type="hidden" name="view" value="{$viewObjId}"/>
          <xsl:choose>
            <xsl:when test="doc-available('Clipboard.content')">
              <xsl:variable name="entries" select="doc('Clipboard.content')/*/*"/>
              <xsl:apply-templates select="$entries"/>
              <input type="submit" name="remove" value="Remove Selected">
                <xsl:if test="not($entries)">
                  <xsl:attribute name="disabled">true</xsl:attribute>
                </xsl:if>
              </input>
              <xsl:text> </xsl:text>
              <input type="submit" name="clear" value="Clear All">
                <xsl:if test="not($entries)">
                  <xsl:attribute name="disabled">true</xsl:attribute>
                </xsl:if>
              </input>
            </xsl:when>
            <xsl:otherwise>
              <input type="submit" name="build" value="Build Clipboard" />
            </xsl:otherwise>
          </xsl:choose>
        </form>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="cb:clipboard/cb:entry">
    <input id="{@id}" name="entryId" value="{@id}" type="radio"/>
    <label for="{@id}">
      <span class="entry_label">
        <xsl:value-of select="@object"/>
        <xsl:if test="normalize-space(@entity) != ''">
          <xsl:text>#</xsl:text>
          <xsl:value-of select="@entity" />
        </xsl:if>
      </span>
      <div class="preview">
        <xsl:value-of select="substring(.,0,80)" />
        <xsl:if test="string-length(.) &gt; 80">...</xsl:if>
      </div>
    </label>
    <hr/>
  </xsl:template>

</xsl:stylesheet>
